#include <cstring>
#include <iostream>
using std::cout;
using std::endl;
//TODO:stack singleton 但是对象数据成员在堆区申请空间
class Computer{
public:
    static Computer & get_instance(const char*brand,float price)
    {
        static Computer ct(brand,price);
        return ct;
    }


    Computer(const Computer &) = delete;
    Computer &operator=(const Computer &) = delete;

    void destory(){
        if(_brand != nullptr){
            delete []_brand;
            _brand = nullptr;
        }
    }
    void print(){
        cout<<_brand<<":"<<_price<<endl;
    }

private :
    Computer (const char*brand,float price)
    :_brand(new char[strlen(brand)+1]())
    ,_price(price) 
    {
    strcpy(_brand,brand);
    }

    ~Computer (){
    }

    char *_brand;
    float _price;
};
void test(){
    Computer &c1 = Computer::get_instance("iqoo",4500);
    c1.print();
    c1.destory();
    Computer &c2 = Computer::get_instance("ooqi",1234);//再次赋值不会起作用  
    c2.print();
   // Computer("iqoo",1234);
   // Computer c3;
   // computer c4 = c1;


}

int main()
{
    

    test ();
    return 0;
}

